<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    
</body>
<script>
    class Person {
        static a = null
        constructor(name){
            this.name = name
            if(!Person.a){
              Person.a = this
            }
           
            return Person.a
        }
    }
const b = new Person("b")
const c = new Person("c")
console.log("~~~~~~b~",b);
console.log("~~~~~~c~",c);
console.log("~~~~~~c~",c===b);

class Singleton {
  static instance = null;

  constructor() {
    if (!Singleton.instance) {
      Singleton.instance = this;
    }

    return Singleton.instance;
  }

  static getInstance() {
    if (!Singleton.instance) {
      Singleton.instance = new Singleton();
    }

    return Singleton.instance;
  }

  // 其他方法和属性...
}
const Singleton1 = new Singleton();
const Singleton2 = new Singleton();
console.log("~~~~~Singleton1~~~~~",Singleton1);
console.log("~~~~~Singleton2~~~~~",Singleton2);
console.log("~~~~~=====~~~~~",Singleton2===Singleton1);

class Animal {
  constructor(name,age){
    this.name = name;
    this.age = age;
  }
  runing(){
    console.log("跑");
  }
}

class Dog extends Animal {
  #count=45;
  constructor(like,name,age){
    super(name,age);
    this.like = like
  }
  swiing(){
    console.log("DDDDDDDD",this.#count);
    console.log("汪汪");
  }
}

const dog1 = new Dog('骨头',"旺财",3)
console.log(dog1.swiing,'~~~~~dog1.swiing~~~~~');
console.log(dog1.runing,'~~~~~dog1.runing~~~~~');
dog1.swiing()
Dog.prototype.sound = function(){
  console.log("汪汪");
}
const dog2 = new Dog('骨头sss',"旺财sss",30)
console.log("~~~~~dog1~~~~~",dog1.count);
dog2.sound()
</script>
</html>